package ${package.Entity};

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yaya.common.object.BaseObject;
import org.springframework.beans.BeanUtils;
import ${config.packageConfig.parent}.dtomain.${table.entityName}Dto;

import lombok.Getter;
import lombok.Setter;

/**
 * ${table.comment}
 *
 * @author ${author}
 * @since ${date[0..10]}
 */
@Getter
@Setter
<#--@TableName("${schemaName}${table.name}")-->
public class ${table.entityName} extends BaseObject {

    <#list table.fields as field>
        /** ${field.comment} */
        <#if field.keyFlag>
        @TableId(type = IdType.ASSIGN_UUID)
        </#if>
        private ${field.propertyType} ${field.propertyName};

    </#list>

  /**
   * 构建${table.comment}
   *
   * @${table.entityName?uncap_first}Dto ${table.comment}传输对象
   * @return ${table.comment}
   */
    // 构建实体类
    public static ${table.entityName} build${table.entityName}(${table.entityName}Dto ${table.entityName?uncap_first}Dto) {
    ${table.entityName} ${table.entityName?uncap_first} = new ${table.entityName}();
    BeanUtils.copyProperties(${table.entityName?uncap_first}Dto, ${table.entityName?uncap_first});
    return ${table.entityName?uncap_first};
    }

<#--    /**-->
<#--    * 构建${table.comment}传输对象-->
<#--    *-->
<#--    * @param ${table.entityName?uncap_first} ${table.comment}-->
<#--    * @return ${table.comment}传输对象-->
<#--    */-->
<#--    // 构建DTO-->
<#--    public static ${table.entityName}Dto build${table.entityName}Dto(${table.entityName} ${table.entityName?uncap_first}) {-->
<#--    ${table.entityName}Dto ${table.entityName?uncap_first}Dto = new ${table.entityName}Dto();-->
<#--    BeanUtils.copyProperties(${table.entityName?uncap_first}, ${table.entityName?uncap_first}Dto);-->
<#--    return ${table.entityName?uncap_first}Dto;-->
<#--    }-->
    /**
    * 构建 ${table.comment} 传输对象
    *
    * @param ${table.entityName?uncap_first} ${table.comment} 传输对象列表
    * @return ${table.comment} 传输对象
    */
    // 构建DTO
    public static ${table.entityName}Dto build${table.entityName}Dto(${table.entityName} ${table.entityName?uncap_first}) {
    ${table.entityName}Dto ${table.entityName?uncap_first}Dto = new ${table.entityName}Dto();
    // 使用 BeanUtils 复制属性
    BeanUtils.copyProperties(${table.entityName?uncap_first}, ${table.entityName?uncap_first}Dto);
    return ${table.entityName?uncap_first}Dto;
    }





  /**
   * 构建${table.comment}列表
   *
   * @param ${table.entityName?uncap_first}Dtos ${table.comment}传输对象列表
   * @return ${table.comment}列表
   */
    // 构建实体类列表
    public static List<${table.entityName}> build${table.entityName}s(List<${table.entityName}Dto> ${table.entityName?uncap_first}Dtos) {
        List<${table.entityName}> ${table.entityName?uncap_first}s = new ArrayList<>();
        ${table.entityName?uncap_first}Dtos.forEach(dto -> ${table.entityName?uncap_first}s.add(build${table.entityName}(dto)));
        return ${table.entityName?uncap_first}s;
        }


    /**
   * 构建${table.comment}传输对象列表
   *
   * @param ${table.entityName?uncap_first}s ${table.comment}列表
   * @return ${table.comment}传输对象列表
   */
    // 构建DTO列表
    public static List<${table.entityName}Dto> build${table.entityName}Dtos(List<${table.entityName}> ${table.entityName?uncap_first}s) {
        List<${table.entityName}Dto> ${table.entityName?uncap_first}Dtos = new ArrayList<>();
            ${table.entityName?uncap_first}s.forEach(entity -> ${table.entityName?uncap_first}Dtos.add(build${table.entityName}Dto(entity)));
            return ${table.entityName?uncap_first}Dtos;
            }

    }



